package servlets.users;

import java.io.IOException;
import java.net.URL;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jsoup.Jsoup;

public class LoginByID extends HttpServlet{
	private static final long serialVersionUID = 1L;
	private static final String LOGINURLBASE = "http://localhost:8080/DatabaseRESTWebService/GetIdUserServlet";
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) {
		String answer, idUser;
		URL url;
		idUser = request.getParameter("idUser");
		
		try {
			url = new URL(LOGINURLBASE + "?idUser=" + idUser);
			answer = Jsoup.connect(url.toString()).ignoreContentType(true).execute().body();
			
			if(answer.equals("null"))
				throw new Exception();
			
			try {
				//write the result as JSon
				response.getWriter().write(answer);
			} catch (IOException e) {
				e.printStackTrace();
			}
		} catch (Exception e1) {
			
		}
		
	}
}